package com.ttg.web.service.Impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.ttg.common.constant.BasicConstant;
import com.ttg.common.dto.TagProducer;
import com.ttg.common.entities.BaseResult;
import com.ttg.common.entities.RattingTask;
import com.ttg.common.enums.*;
import com.ttg.common.exception.BaseException;
import com.ttg.common.utils.DateTimeUtil;
import com.ttg.common.utils.JsonUtils;
import com.ttg.common.utils.QxAndJhUtil;
import com.ttg.model.dto.GetBankInfoDto;
import com.ttg.model.dto.MctGrowAndIntegralSumDto;
import com.ttg.model.dto.SaveGrowthAndIntegralDto;
import com.ttg.model.pojo.*;
import com.ttg.model.vo.VipRatingInfoVo;
import com.ttg.web.dao.*;
import com.ttg.web.service.VipBankInfoManagementService;
import com.ttg.web.service.VipGrowthIntegrationManagementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @author zhangHongYuan
 * @description
 * @date 2023/7/17 11:27
 */
@Service
@Slf4j
public class VipBankInfoManagementServiceImpl implements VipBankInfoManagementService {

    @Autowired
    private VipGradeConfigDao vipGradeConfigDao;

    @Autowired
    private VipInfoDao couponVipDao;
    @Autowired
    private VipRattingConfigDao vipGradeRattingDao;

    @Autowired
    private VipBankInfoDao couponVipBankInfoDao;

    @Autowired
    private RulesListDao rulesListDao;

    @Autowired
    private VipMctInfoDao vipMctInfoDao;

    @Autowired
    private VipGrowDetailDao vipGrowDetailDao;

    @Value("${autotask.pageSize}")
    private Integer pageSize;


    @Autowired
    private ConditionsNameDao conditionsNameDao;

    @Autowired
    private BankPublicPrimitiveDao bankPublicPrimitiveDao;


    @Autowired
    private BankCardDataInfoDao bankCardDataInfoDao;

    @Autowired
    private BankProductDataInfoDao bankProductDataInfoDao;

    @Autowired
    private BankCustomerSignInfoDao bankCustomerSignInfoDao;

    @Autowired
    private BankCardBindingInfoDao bankCardBindingInfoDao;

    @Autowired
    private BankPublicTradePrimitiveDao bankPublicTradePrimitiveDao;

    @Autowired
    private VipInfoDao vipInfoDao;

    @Autowired
    private VipLastGradeBakDao vipLastGradeBakDao;

    @Autowired
    private VipNextGradeTempDao vipNextGradeTempDao;

    @Autowired
    private PlatformTransactionManager transactionManager;

//    @Autowired
//    private VipBankInfoService vipBankInfoService;

    @Autowired
    private BankPrivatePrimitiveDao bankPrivatePrimitiveDao;

    @Override
    public boolean startVipRating(List<Long> ids) {
        List<VipInfo> list = null;
        if (CollectionUtils.isEmpty(ids)) {
            list = couponVipDao.allByStatus();
        } else {
            list = couponVipDao.QueryByIdsAndStatus(ids);
        }
        List<RulesList> rulesLists = rulesListDao.allByStatus();
        List<VipRatingConfig> vipRatings = vipGradeRattingDao.list();

        if (CollectionUtils.isEmpty(rulesLists) || CollectionUtils.isEmpty(vipRatings)) {
            log.warn("没有任务规则数据");
            throw new BaseException(ErrorCodeEnums.RULES_IS_NULL);
        }
        //获取银行信息
        GetBankInfoDto dto = new GetBankInfoDto();
        dto.setVipId(list.stream().map(VipInfo::getVipId).collect(Collectors.toList()));
        // vipBankInfoService.getBankInfo(dto); todo 接口暂无 先注释掉不执行
        //初期评分
        boolean b = startVipRating1(list);
        if (!b) {
            throw new BaseException(ErrorCodeEnums.GROWTH_START_IS_ERROR);
        }
        return b;
//        startVipRating2(list);
//        startVipRating3(list);
//        startVipRating4(list);
//        startVipRating5(list);
//        startVipRating6(list);
//        startVipRating7(list);
//        for (VipInfo vipInfo : list) {
//
//            Long growth = BasicConstant.LONG_0;
//            for (RulesList rulesList : rulesLists) {
//                List<VipRatingConfig> collect = vipRatings.stream().filter(r -> r.getRulesId().equals(Long.valueOf(rulesList.getId()))).collect(Collectors.toList());

//                switch (rulesList.getId()) {
//                    case 1:
//                        VipBankInfo lastOneByDate = couponVipBankInfoDao.getLastOneByDate(vipInfo.getVipId());
//                        for (VipRatingConfig vipRatingConfig : collect) {
//                            Long dmd= Long.valueOf(lastOneByDate.getDmdepBal());
//                            if (dmd>=vipRatingConfig.getRatingStart()&&dmd<vipRatingConfig.getRatingEnd()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }else if (vipRatingConfig.getRatingEnd().equals(BasicConstant.LONG_0)&&dmd>=vipRatingConfig.getRatingStart()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }
//                        }
//                        break;
//                    case 2:
//                        LocalDate today = LocalDate.now();
//
//                        // 获取上个月的月初（1号）和月底（最后一天）的日期
//                        LocalDate firstDayOfLastMonth = today.minusMonths(1).withDayOfMonth(1);
//                        LocalDate lastDayOfLastMonth = today.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
//                        List<VipBankInfo> byVipIdAndTime = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), firstDayOfLastMonth, lastDayOfLastMonth);
//                        long sum = byVipIdAndTime.stream().mapToLong(value -> Long.parseLong(value.getDmdepBal())).sum();
//                        int i = lastDayOfLastMonth.getDayOfMonth() - firstDayOfLastMonth.getDayOfMonth() + 1;
//                        long l = sum / i;
//                        if (l<BasicConstant.INT_0){
//                            l=BasicConstant.INT_0;
//                        }
//                        for (VipRatingConfig vipRatingConfig : collect) {
//                            if (l>=vipRatingConfig.getRatingStart()&&l<vipRatingConfig.getRatingEnd()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }else if (vipRatingConfig.getRatingEnd().equals(BasicConstant.LONG_0)&&l>=vipRatingConfig.getRatingStart()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }
//                        }
//                        break;
//                    case 3:
//                        LocalDate date = LocalDate.now();
//
//                        // 获取上个月的月初（1号）和月底（最后一天）的日期
//                        LocalDate date1 = date.minusMonths(1);
//                        LocalDate date2 = date.minusMonths(2);
//                        LocalDate date1FirstDayOfLastMonth = date1.minusMonths(1).withDayOfMonth(1);
//                        LocalDate date1LastDayOfLastMonth = date1.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
//                        LocalDate date2FirstDayOfLastMonth = date2.minusMonths(1).withDayOfMonth(1);
//                        LocalDate date2LastDayOfLastMonth = date2.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
//
//                        List<VipBankInfo> vipBankInfos = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), date1FirstDayOfLastMonth, date1LastDayOfLastMonth);
//                        List<VipBankInfo> vipBankInfos2 = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), date2FirstDayOfLastMonth, date2LastDayOfLastMonth);
//                        long sum1 = vipBankInfos.stream().mapToLong(value -> Long.parseLong(value.getDmdepBal())).sum() / ( date1LastDayOfLastMonth.getDayOfMonth() - date1FirstDayOfLastMonth.getDayOfMonth() + 1);
//                        long sum2 = vipBankInfos2.stream().mapToLong(value -> Long.parseLong(value.getDmdepBal())).sum() / ( date1LastDayOfLastMonth.getDayOfMonth() - date1FirstDayOfLastMonth.getDayOfMonth() + 1);
//                        long l1 = sum1 - sum2;
//                        if (CollectionUtils.isEmpty(vipBankInfos)||CollectionUtils.isEmpty(vipBankInfos2)
//                         || sum1<BasicConstant.LONG_1||sum2<BasicConstant.LONG_1||l1<BasicConstant.LONG_0){
//                            continue;
//                        }
//                        for (VipRatingConfig vipRatingConfig : collect) {
//                            if (l1>=vipRatingConfig.getRatingStart()&&l1<vipRatingConfig.getRatingEnd()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }else if (vipRatingConfig.getRatingEnd().equals(BasicConstant.LONG_0)&&l1>=vipRatingConfig.getRatingStart()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }
//                        }
//                        break;
//                    case 4:
//                        Long continuousMonth = collect.get(0).getContinuousMonth();
//                        LocalDate now = LocalDate.now();
//                        LocalDate date3 = now.minusMonths(continuousMonth);
//                        LocalDate date3FirstDayOfLastMonth = date3.minusMonths(1).withDayOfMonth(1);
//                        LocalDate date3LastDayOfLastMonth = date3.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
//                        List<VipBankInfo> vipBankInfos3 = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), date3FirstDayOfLastMonth, date3LastDayOfLastMonth);
//                        long sum3 = vipBankInfos3.stream().mapToLong(value -> Long.parseLong(value.getDmdepBal())).sum() / ( date3FirstDayOfLastMonth.getDayOfMonth() - date3LastDayOfLastMonth.getDayOfMonth() + 1);
//                        VipRatingConfig vipRatingConfig1 =null;
//                        for (VipRatingConfig vipRatingConfig : collect) {
//                            if (sum3>=vipRatingConfig.getRatingStart()&&sum3<vipRatingConfig.getRatingEnd()){
//                                vipRatingConfig1=vipRatingConfig;
//                            }else if (vipRatingConfig.getRatingEnd().equals(BasicConstant.LONG_0)&&sum3>=vipRatingConfig.getRatingStart()){
//                                vipRatingConfig1=vipRatingConfig;
//                            }
//                        }
//                        Boolean flag = true;
//                        continuousMonth-=continuousMonth;
//                        for (; continuousMonth >0 ; continuousMonth--) {
//                            LocalDate date4 = now.minusMonths(continuousMonth);
//                            LocalDate date4FirstDayOfLastMonth = date4.minusMonths(1).withDayOfMonth(1);
//                            LocalDate date4LastDayOfLastMonth = date4.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
//                            List<VipBankInfo> vipBankInfos4 = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), date4FirstDayOfLastMonth, date4LastDayOfLastMonth);
//                            long sum4 = vipBankInfos4.stream().mapToLong(value -> Long.parseLong(value.getDmdepBal())).sum() / ( date3FirstDayOfLastMonth.getDayOfMonth() - date3LastDayOfLastMonth.getDayOfMonth() + 1);
//                            if (sum4<vipRatingConfig1.getRatingStart()){
//                                flag=false;
//                            }
//                        }
//                        if (flag){
//                            growth+=vipRatingConfig1.getGrowthValue();
//                        }
//                        break;
//                    case 5:
//                        VipBankInfo lastOneByDate1 = couponVipBankInfoDao.getLastOneByDate(vipInfo.getVipId());
//                        for (VipRatingConfig vipRatingConfig : collect) {
//                            Long bal= Long.valueOf(lastOneByDate1.getLoanBal());
//                            if (bal>=vipRatingConfig.getRatingStart()&&bal<vipRatingConfig.getRatingEnd()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }else if (vipRatingConfig.getRatingEnd().equals(BasicConstant.LONG_0)&&bal>=vipRatingConfig.getRatingStart()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }
//                        }
//                        break;
//                    case 6:
//                        VipBankInfo lastOneByDate2 = couponVipBankInfoDao.getLastOneByDate(vipInfo.getVipId());
//                        for (VipRatingConfig vipRatingConfig : collect) {
//                            Long number= lastOneByDate2.getTradeNumber();
//                            if (number>=vipRatingConfig.getRatingStart()&&number<vipRatingConfig.getRatingEnd()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }else if (vipRatingConfig.getRatingEnd().equals(BasicConstant.LONG_0)&&number>=vipRatingConfig.getRatingStart()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }
//                        }
//                        break;
//                    case 7:
//                        VipBankInfo lastOneByDate3 = couponVipBankInfoDao.getLastOneByDate(vipInfo.getVipId());
//                        for (VipRatingConfig vipRatingConfig : collect) {
//                            Long number=  lastOneByDate3.getTradeAmount().longValue();
//                            if (number>=vipRatingConfig.getRatingStart()&&number<vipRatingConfig.getRatingEnd()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }else if (vipRatingConfig.getRatingEnd().equals(BasicConstant.LONG_0)&&number>=vipRatingConfig.getRatingStart()){
//                                growth+=vipRatingConfig.getGrowthValue();
//                            }
//                        }
//                        break;
//                    default:
//                        break;
//
//                }
//            }
//
//        }
    }

    @Autowired
    private VipGrowthIntegrationManagementService vipGrowthIntegrationManagementService;

    @Override
    public boolean startVipRating1(List<VipInfo> list) {
        if (CollectionUtils.isEmpty(list)) {
            list = couponVipDao.allByStatus();
        }
        RulesList byId = rulesListDao.getById(RulesTypeEnum.TYPE_1.getCode());
        List<VipRatingConfig> rattingRulesListByRulesId = vipGradeRattingDao.getRattingRulesListByRulesId(String.valueOf(byId.getId()));
//        Long growth = 0L;
        Long integral = 0L;
        for (VipInfo vipInfo : list) {

            List<VipBankInfo> byLately = couponVipBankInfoDao.getByLately(vipInfo.getVipId());
            if (CollectionUtils.isEmpty(byLately)) {
                continue;
            }
            for (VipRatingConfig vipRatingConfig : rattingRulesListByRulesId) {
                for (VipBankInfo vipBankInfo : byLately) {
                    Long dmd = vipBankInfo.getDmdepBal().add(vipBankInfo.getTmdepBal()).longValue();
                    if (diffAmount(vipRatingConfig, dmd)) {
//                        growth = vipRatingConfig.getGrowthValue();
                        integral = vipRatingConfig.getScore();

                        SaveGrowthAndIntegralDto dto = new SaveGrowthAndIntegralDto();
                        dto.setVipId(vipInfo.getVipId());
                        dto.setBankAccount(vipBankInfo.getBankCarNo());
                        dto.setRulesId(byId.getId().longValue());
//                        dto.setGrowthValue(growth);
                        dto.setIntegral(integral);
//                        dto.setMaxGrowth(byId.getGrowthMax());

                        boolean b = vipGrowthIntegrationManagementService.saveGrowthAndIntegral(dto);
                        if (!b) {
                            log.error("startVipRating1 error====>{}", dto);
                        }
                    }
                }

            }
        }
        return true;
    }

    public boolean diffAmount(VipRatingConfig vipRatingConfig, Long value) {
        if (value >= vipRatingConfig.getRatingStart() && value < vipRatingConfig.getRatingEnd()) {
            return true;
        } else if (vipRatingConfig.getRatingEnd().equals(BasicConstant.LONG_0) && value >= vipRatingConfig.getRatingStart()) {
            return true;
        }
        return false;
    }

    public boolean startVipRating2(List<VipInfo> list) {
        if (CollectionUtils.isEmpty(list)) {
            list = couponVipDao.allByStatus();
        }
        RulesList byId = rulesListDao.getById(RulesTypeEnum.TYPE_2.getCode());
        List<VipRatingConfig> rattingRulesListByRulesId = vipGradeRattingDao.getRattingRulesListByRulesId(String.valueOf(byId.getId()));
        for (VipInfo vipInfo : list) {


            LocalDate today = LocalDate.now();

            // 获取上个月的月初（1号）和月底（最后一天）的日期
            LocalDate firstDayOfLastMonth = today.minusMonths(1).withDayOfMonth(1);
            LocalDate lastDayOfLastMonth = today.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
            List<VipBankInfo> byVipIdAndTime = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), firstDayOfLastMonth, lastDayOfLastMonth);
            if (CollectionUtils.isEmpty(byVipIdAndTime)) {
                continue;
            }
            int i = lastDayOfLastMonth.getDayOfMonth() - firstDayOfLastMonth.getDayOfMonth() + 1;
            Map<Long, List<VipBankInfo>> collect = byVipIdAndTime.stream().collect(Collectors.groupingBy(VipBankInfo::getBankCarNo));
            for (VipRatingConfig vipRatingConfig : rattingRulesListByRulesId) {
                collect.forEach((k, v) -> {

                    long sum = v.stream().mapToLong(a -> a.getDmdepBal().longValue()).sum() + v.stream().mapToLong(a -> a.getTmdepBal().longValue()).sum();

                    long l = sum / i;
                    if (l < BasicConstant.INT_0) {
                        l = BasicConstant.INT_0;
                    }
                    if (!diffAmount(vipRatingConfig, l)) {
                        return;
                    }
                    SaveGrowthAndIntegralDto dto = new SaveGrowthAndIntegralDto();
                    dto.setVipId(vipInfo.getVipId());
                    dto.setBankAccount(k);
                    dto.setRulesId(byId.getId().longValue());
//                    dto.setGrowthValue(vipRatingConfig.getGrowthValue());
                    dto.setIntegral(vipRatingConfig.getScore());
//                    dto.setMaxGrowth(byId.getGrowthMax());

                    boolean b = vipGrowthIntegrationManagementService.saveGrowthAndIntegral(dto);
                    if (!b) {
                        log.error("startVipRating1 error====>{}", dto);
                    }
                });


            }

        }

        return true;
    }

    public boolean startVipRating3(List<VipInfo> list) {
        if (CollectionUtils.isEmpty(list)) {
            list = couponVipDao.allByStatus();
        }
        RulesList byId = rulesListDao.getById(RulesTypeEnum.TYPE_3.getCode());
        List<VipRatingConfig> rattingRulesListByRulesId = vipGradeRattingDao.getRattingRulesListByRulesId(String.valueOf(byId.getId()));
        for (VipInfo vipInfo : list) {

            LocalDate date = LocalDate.now();

            // 获取上个月的月初（1号）和月底（最后一天）的日期
            LocalDate date1 = date.minusMonths(1);
            LocalDate date2 = date.minusMonths(2);
            LocalDate date1FirstDayOfLastMonth = date1.withDayOfMonth(1);
            LocalDate date1LastDayOfLastMonth = date1.with(TemporalAdjusters.lastDayOfMonth());
            LocalDate date2FirstDayOfLastMonth = date2.withDayOfMonth(1);
            LocalDate date2LastDayOfLastMonth = date2.with(TemporalAdjusters.lastDayOfMonth());

            List<VipBankInfo> vipBankInfos = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), date1FirstDayOfLastMonth, date1LastDayOfLastMonth);
            List<VipBankInfo> vipBankInfos2 = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), date2FirstDayOfLastMonth, date2LastDayOfLastMonth);
            if (CollectionUtils.isEmpty(vipBankInfos) || CollectionUtils.isEmpty(vipBankInfos2)) {
                continue;
            }
            int date1Num = date1LastDayOfLastMonth.getDayOfMonth() - date1FirstDayOfLastMonth.getDayOfMonth() + 1;
            int date2Num = date2LastDayOfLastMonth.getDayOfMonth() - date2FirstDayOfLastMonth.getDayOfMonth() + 1;
            Map<Long, List<VipBankInfo>> collect = vipBankInfos.stream().collect(Collectors.groupingBy(VipBankInfo::getBankCarNo));
            Map<Long, List<VipBankInfo>> collect2 = vipBankInfos2.stream().collect(Collectors.groupingBy(VipBankInfo::getBankCarNo));
            for (VipRatingConfig vipRatingConfig : rattingRulesListByRulesId) {

                collect.forEach((k, v) -> {

                    long sum = (v.stream().mapToLong(a -> a.getDmdepBal().longValue()).sum() + v.stream().mapToLong(a -> a.getTmdepBal().longValue()).sum()) / date1Num;
                    long sum1 = (collect2.get(k).stream().mapToLong(a -> a.getDmdepBal().longValue()).sum() + v.stream().mapToLong(a -> a.getTmdepBal().longValue()).sum()) / date2Num;

                    long l = sum - sum1;
                    if (l < BasicConstant.INT_0) {
                        return;
                    }
                    if (!diffAmount(vipRatingConfig, l)) {
                        return;
                    }
                    SaveGrowthAndIntegralDto dto = new SaveGrowthAndIntegralDto();
                    dto.setVipId(vipInfo.getVipId());
                    dto.setBankAccount(k);
                    dto.setRulesId(byId.getId().longValue());
//                    dto.setGrowthValue(vipRatingConfig.getGrowthValue());
                    dto.setIntegral(vipRatingConfig.getScore());
//                    dto.setMaxGrowth(byId.getGrowthMax());

                    boolean b = vipGrowthIntegrationManagementService.saveGrowthAndIntegral(dto);
                    if (!b) {
                        log.error("startVipRating1 error====>{}", dto);
                    }
                });


            }

        }

        return true;
    }

    public boolean startVipRating4(List<VipInfo> list) {
        if (CollectionUtils.isEmpty(list)) {
            list = couponVipDao.allByStatus();
        }
        RulesList byId = rulesListDao.getById(RulesTypeEnum.TYPE_4.getCode());
        List<VipRatingConfig> rattingRulesListByRulesId = vipGradeRattingDao.getRattingRulesListByRulesId(String.valueOf(byId.getId()));
        if (CollectionUtils.isEmpty(rattingRulesListByRulesId)) {
            return false;
        }
        for (VipInfo vipInfo : list) {
            LocalDate now = LocalDate.now();
            LocalDate date3 = now.minusMonths(rattingRulesListByRulesId.get(0).getContinuousMonth());
            LocalDate date3FirstDayOfLastMonth = date3.withDayOfMonth(1);
            LocalDate date3LastDayOfLastMonth = date3.with(TemporalAdjusters.lastDayOfMonth());
            List<VipBankInfo> vipBankInfos = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), date3FirstDayOfLastMonth, date3LastDayOfLastMonth);
            if (CollectionUtils.isEmpty(vipBankInfos)) {
                continue;
            }
            Map<Long, List<VipBankInfo>> collect = vipBankInfos.stream().collect(Collectors.groupingBy(VipBankInfo::getBankCarNo));


            for (VipRatingConfig vipRatingConfig : rattingRulesListByRulesId) {


                collect.forEach((k, v) -> {

                    long sum = v.stream().mapToLong(a -> a.getDmdepBal().longValue()).sum() + v.stream().mapToLong(a -> a.getTmdepBal().longValue()).sum() / (date3LastDayOfLastMonth.getDayOfMonth() - date3FirstDayOfLastMonth.getDayOfMonth() + 1);
                    if (!diffAmount(vipRatingConfig, sum)) {
                        return;
                    }
                    boolean flag = true;
                    Long continuousMonth = vipRatingConfig.getContinuousMonth();
                    continuousMonth -= continuousMonth;
                    for (; continuousMonth > 0; continuousMonth--) {
                        LocalDate date4 = now.minusMonths(continuousMonth);
                        LocalDate date4FirstDayOfLastMonth = date4.minusMonths(1).withDayOfMonth(1);
                        LocalDate date4LastDayOfLastMonth = date4.minusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
                        List<VipBankInfo> vipBankInfos4 = couponVipBankInfoDao.getByVipIdAndTime(vipInfo.getVipId(), date4FirstDayOfLastMonth, date4LastDayOfLastMonth);
                        long sum4 = (vipBankInfos4.stream().mapToLong(a -> a.getDmdepBal().longValue()).sum() + vipBankInfos4.stream().mapToLong(a -> a.getTmdepBal().longValue()).sum()) / (date4LastDayOfLastMonth.getDayOfMonth() - date4FirstDayOfLastMonth.getDayOfMonth() + 1);
                        if (sum4 < vipRatingConfig.getRatingStart()) {
                            flag = false;
                        }
                    }
                    if (flag) {

                        SaveGrowthAndIntegralDto dto = new SaveGrowthAndIntegralDto();
                        dto.setVipId(vipInfo.getVipId());
                        dto.setBankAccount(k);
                        dto.setRulesId(byId.getId().longValue());
//                        dto.setGrowthValue(vipRatingConfig.getGrowthValue());
                        dto.setIntegral(vipRatingConfig.getScore());
//                        dto.setMaxGrowth(byId.getGrowthMax());

                        boolean b = vipGrowthIntegrationManagementService.saveGrowthAndIntegral(dto);
                        if (!b) {
                            log.error("startVipRating1 error====>{}", dto);
                        }
                    }
                });


            }

        }

        return true;
    }


    public boolean startVipRating5(List<VipInfo> list) {
        if (CollectionUtils.isEmpty(list)) {
            list = couponVipDao.allByStatus();
        }
        RulesList byId = rulesListDao.getById(RulesTypeEnum.TYPE_5.getCode());
        List<VipRatingConfig> rattingRulesListByRulesId = vipGradeRattingDao.getRattingRulesListByRulesId(String.valueOf(byId.getId()));
        for (VipInfo vipInfo : list) {

            List<VipBankInfo> byLately = couponVipBankInfoDao.getByLately(vipInfo.getVipId());
            if (CollectionUtils.isEmpty(byLately)) {
                continue;
            }
            for (VipRatingConfig vipRatingConfig : rattingRulesListByRulesId) {
                for (VipBankInfo vipBankInfo : byLately) {
                    Long dmd = vipBankInfo.getLoanBal().longValue();
                    if (diffAmount(vipRatingConfig, dmd)) {
                        SaveGrowthAndIntegralDto dto = new SaveGrowthAndIntegralDto();
                        dto.setVipId(vipInfo.getVipId());
                        dto.setBankAccount(vipBankInfo.getBankCarNo());
                        dto.setRulesId(byId.getId().longValue());
//                        dto.setGrowthValue(vipRatingConfig.getGrowthValue());
                        dto.setIntegral(vipRatingConfig.getScore());
//                        dto.setMaxGrowth(byId.getGrowthMax());

                        boolean b = vipGrowthIntegrationManagementService.saveGrowthAndIntegral(dto);
                        if (!b) {
                            log.error("startVipRating1 error====>{}", dto);
                        }
                    }
                }

            }
        }
        return true;
    }

    public boolean startVipRating6(List<VipInfo> list) {
        if (CollectionUtils.isEmpty(list)) {
            list = couponVipDao.allByStatus();
        }
        RulesList byId = rulesListDao.getById(RulesTypeEnum.TYPE_6.getCode());
        List<VipRatingConfig> rattingRulesListByRulesId = vipGradeRattingDao.getRattingRulesListByRulesId(String.valueOf(byId.getId()));
        LocalDate now = LocalDate.now();
        for (VipInfo vipInfo : list) {
            List<VipMctInfo> mctInfoByVipIdAndDate = vipMctInfoDao.findMctInfoByVipIdAndLatelyDate(vipInfo.getVipId(), now.minusDays(1));
            if (CollectionUtils.isEmpty(mctInfoByVipIdAndDate)) {
                continue;
            }
            for (VipRatingConfig vipRatingConfig : rattingRulesListByRulesId) {
                for (VipMctInfo vipBankInfo : mctInfoByVipIdAndDate) {
                    Long dmd = vipBankInfo.getTradeNum();
                    if (diffAmount(vipRatingConfig, dmd)) {
                        SaveGrowthAndIntegralDto dto = new SaveGrowthAndIntegralDto();

                        dto.setVipId(vipInfo.getVipId());
                        dto.setMctNo(vipBankInfo.getMctNo().longValue());
                        dto.setRulesId(byId.getId().longValue());
//                        dto.setGrowthValue(vipRatingConfig.getGrowthValue());
                        dto.setIntegral(vipRatingConfig.getScore());
//                        dto.setMaxGrowth(byId.getGrowthMax());

                        boolean b = vipGrowthIntegrationManagementService.saveGrowthAndIntegral(dto);
                        if (!b) {
                            log.error("startVipRating1 error====>{}", dto);
                        }
                    }
                }

            }
        }
        return true;
    }

    public boolean startVipRating7(List<VipInfo> list) {
        if (CollectionUtils.isEmpty(list)) {
            list = couponVipDao.allByStatus();
        }
        LocalDate now = LocalDate.now();
        RulesList byId = rulesListDao.getById(RulesTypeEnum.TYPE_7.getCode());
        List<VipRatingConfig> rattingRulesListByRulesId = vipGradeRattingDao.getRattingRulesListByRulesId(String.valueOf(byId.getId()));
        for (VipInfo vipInfo : list) {

            List<VipMctInfo> mctInfoByVipIdAndDate = vipMctInfoDao.findMctInfoByVipIdAndLatelyDate(vipInfo.getVipId(), now.minusDays(1));
            for (VipRatingConfig vipRatingConfig : rattingRulesListByRulesId) {
                for (VipMctInfo vipBankInfo : mctInfoByVipIdAndDate) {
                    Long dmd = vipBankInfo.getTradeAmount().longValue();
                    if (diffAmount(vipRatingConfig, dmd)) {
                        SaveGrowthAndIntegralDto dto = new SaveGrowthAndIntegralDto();
                        dto.setVipId(vipInfo.getVipId());
                        dto.setMctNo(vipBankInfo.getMctNo().longValue());
                        dto.setRulesId(byId.getId().longValue());
//                        dto.setGrowthValue(vipRatingConfig.getGrowthValue());
                        dto.setIntegral(vipRatingConfig.getScore());
//                        dto.setMaxGrowth(byId.getGrowthMax());

                        boolean b = vipGrowthIntegrationManagementService.saveGrowthAndIntegral(dto);
                        if (!b) {
                            log.error("startVipRating1 error====>{}", dto);
                        }
                    }
                }

            }
        }
        return true;
    }


    @RattingTask(taskEnum = TaskEnum.VIP_RATING_AUM)
    public BaseResult startVipRatingAUM() {
        return vipSumGrowAndIntegral(RulesTypeEnum.TYPE_12);
    }

    @Override
    public VipRatingInfoVo getVipRating(Long vipId) {
        VipInfo byId = couponVipDao.getById(vipId);
        if (Objects.isNull(byId)) {
            throw new BaseException(ErrorCodeEnums.VIP_IS_NOT_EXIST);
        }
        VipRatingInfoVo vipRatingInfoVo = new VipRatingInfoVo();
        if (Objects.nonNull(byId.getVipGrade())) {

            vipRatingInfoVo.setVipId(String.valueOf(byId.getVipId()));
//            vipRatingInfoVo.setGrowthValue(String.valueOf(byId.getVipNowGrow()));
            vipRatingInfoVo.setIntegration(String.valueOf(byId.getVipIntegrationAmount()));
            vipRatingInfoVo.setGrade(String.valueOf(byId.getVipGrade()));
            vipRatingInfoVo.setDate(DateTimeUtil.formatYYYY_MM_DD(byId.getVipGradeDate()));
            return vipRatingInfoVo;
        }
        List<VipGradeConfig> list = vipGradeConfigDao.list();
        if (CollectionUtils.isEmpty(list)) {
            throw new BaseException(ErrorCodeEnums.VIP_GRADE_IS_NULL);
        }

//        for (VipGradeConfig vipGradeConfig : list) {
//            if (byId.getVipNowGrow() >= vipGradeConfig.getGrowthStartRange() && byId.getVipNowGrow() < vipGradeConfig.getGrowthEndRange()) {
//                vipRatingInfoVo.setGrade(String.valueOf(vipGradeConfig.getVipGrade()));
//                byId.setVipGrade(vipGradeConfig.getVipGrade());
//                LocalDate localDate = LocalDate.now().plusMonths(vipGradeConfig.getDefaultTime());
//                byId.setVipGradeDate(localDate);
//                byId.setUpdateTime(LocalDateTime.now());
//                byId.setVipGradeStartDate(LocalDate.now());
//                vipRatingInfoVo.setDate(DateTimeUtil.formatYYYY_MM_DD(localDate));
//                couponVipDao.updateById(byId);
//            }
//        }
        vipRatingInfoVo.setVipId(String.valueOf(byId.getVipId()));
//        vipRatingInfoVo.setGrowthValue(String.valueOf(byId.getVipNowGrow()));
        vipRatingInfoVo.setIntegration(String.valueOf(byId.getVipIntegrationAmount()));
        return vipRatingInfoVo;
    }

    @Override
    @RattingTask(taskEnum = TaskEnum.EDIT_VIP_RATING)
    public boolean editVipRating() {
        LocalDate now = LocalDate.now();
        Integer date = Integer.valueOf(DateTimeUtil.formatYYYYMMDD(now));
        //备份是否有效（备份有效期与等级更新时间一致，为一个月）
        Integer checkDate = Integer.valueOf(DateTimeUtil.formatYYYYMMDD(now.minusMonths(BasicConstant.INT_3)));
        VipLastGradeBak bakRuslt = vipLastGradeBakDao.checkBakResultByDate(checkDate);
        //本次评级未备份
        if (Objects.isNull(bakRuslt)){
            //清除之前的备份
            vipLastGradeBakDao.truncateOldRecords();
            //添加事务确保备份一次备份完全
            DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
            //隔离级别
            definition.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
            //传播行为
            definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
            TransactionStatus status = transactionManager.getTransaction(definition);
            try {
                //重新备份
                vipLastGradeBakDao.vipBak(date);
                transactionManager.commit(status);
            }catch (Exception e){
                transactionManager.rollback(status);
                log.error("个人会员等级备份失败，日期"+date+"==================>{}",e.getMessage());
                throw  e;
            }
        }
        //清除上次评级结果
        vipNextGradeTempDao.truncateOldRecords();
        //评级
        vipNextGradeTempDao.vipRating(date);
        VipInfo vip = vipInfoDao.getLastVipId();
        Long idStart = BasicConstant.LONG_1;
        Long lastId = vip.getVipId();
        while (true){
            if (idStart > lastId){
                break;
            }
            Long idEnd = idStart + 10000L;
            vipInfoDao.rattingGradeByBatch(idStart,idEnd);
            idStart = idEnd;
        }
        return true;
    }

    @Override
    @RattingTask(taskEnum = TaskEnum.NEW_VIP_RATING)
    public boolean newVipRating() {
        return vipInfoDao.newVipRating();
    }

//
//    @Override
//    public boolean editVipRating() {
//
//        List<VipGradeConfig> list = vipGradeConfigDao.getVipGradeByType(GradeTypeEnum.TYPE_PRIVATE.getValue());
//        if (CollectionUtils.isEmpty(list)) {
//            throw new BaseException(ErrorCodeEnums.VIP_GRADE_IS_NULL);
//        }
//        for (VipGradeConfig vipGradeConfig : list) {
//            couponVipDao.editVipRatingByVipGradeConfig(vipGradeConfig);
//        }
//        return true;
//    }

    @Override
    public BaseResult getMemberRatting() {
//        List<VipRatingConfig> list = vipGradeRattingDao.list();
//        if (CollectionUtils.isEmpty(list)) {
//            log.warn("【MemberManagementServiceImpl getMemberRatting】 未配置评分有效期");
//            return BaseResult.defaultFail();
//        }
//        VipRatingConfig couponVipRating = list.get(0);
//        LocalDate settingTime = couponVipRating.getSettingTime();
//        LocalDate localDate = settingTime.plusMonths(couponVipRating.getSettingDate());
//
//        boolean equal = localDate.isEqual(LocalDate.now());
//        if (!equal) {
//            return BaseResult.success(equal);
//        }
//        List<VipRatingConfig> type1 = list.stream().filter(l -> "1".equals(l.getRatingType())).collect(Collectors.toList());
//        List<VipRatingConfig> type2 = list.stream().filter(l -> "2".equals(l.getRatingType())).collect(Collectors.toList());
//        List<VipRatingConfig> type3 = list.stream().filter(l -> "3".equals(l.getRatingType())).collect(Collectors.toList());
//
//        List<VipInfo> couponVips = couponVipDao.allByStatus();
//        couponVips.forEach(vip -> {
//            //todo 向银行请求数据 无环境 暂时省略
//            BankMemberGradeDto dto = new BankMemberGradeDto();
//            BankMemberGradeDto2 product = dto.getProduct();
//            //没有钱款数据 跳过
//            if (Objects.isNull(product)) {
//                return;
//            }
//            Long dmdepBal = Long.valueOf(product.getDmdepBal());
//            Long tmdepBal = Long.valueOf(product.getTmdepBal());
//            Long l = dmdepBal + tmdepBal;
//            Long loanBal = Long.valueOf(product.getLoanBal());
//            Long chrtcBal = Long.valueOf(product.getChrtcBal());
//
//            Long sco = 0L;
//            for (VipRatingConfig vipRating : type1) {
//                if (l <= vipRating.getRatingEnd() && l > vipRating.getRatingStart()) {
//                    sco += vipRating.getScore();
//                }
//            }
//            for (VipRatingConfig vipRating : type2) {
//                if (loanBal <= vipRating.getRatingEnd() && loanBal > vipRating.getRatingStart()) {
//                    sco += vipRating.getScore();
//                }
//            }
//            for (VipRatingConfig vipRating : type3) {
//                if (chrtcBal <= vipRating.getRatingEnd() && chrtcBal > vipRating.getRatingStart()) {
//                    sco += vipRating.getScore();
//                }
//            }
//            VipBankInfo couponVipBankInfo = new VipBankInfo();
//            couponVipBankInfo.setLbls(Arrays.toString(dto.getLbls()));
//            couponVipBankInfo.setCstId(dto.getCstId());
//            couponVipBankInfo.setCstName(dto.getCstName());
//            couponVipBankInfo.setCrdtNo(dto.getCrdtNo());
//            couponVipBankInfo.setCstGrdCd(dto.getCstGrdCd());
//            couponVipBankInfo.setDmdepBal(product.getDmdepBal());
//            couponVipBankInfo.setTmdepBal(product.getTmdepBal());
//            couponVipBankInfo.setLoanBal(product.getLoanBal());
//            couponVipBankInfo.setChrtcBal(product.getChrtcBal());
//            couponVipBankInfo.setShrAmtBal(product.getShrAmtBal());
//            couponVipBankInfo.setCrCrdBillAmt(product.getCrCrdBillAmt());
//            couponVipBankInfo.setScoring(sco);
//            couponVipBankInfo.setVipId(vip.getVipId());
//            couponVipBankInfo.setTime(localDate);
//            couponVipBankInfoDao.save(couponVipBankInfo);
//        });
//
//        list.forEach(l -> l.setSettingTime(localDate));
//        boolean b = vipGradeRattingDao.saveOrUpdateBatch(list);
//        return BaseResult.success(b);
        return null;
    }

    @Override
    public BaseResult editMemberGrade() {

//        List<VipInfo> couponVips = couponVipDao.allByStatus();
//        List<VipGradeConfig> list = vipGradeConfigDao.list();
//        couponVips.forEach(couponVip -> {
//            VipGradeConfig vipGradeConfig = null;
//            for (VipGradeConfig config : list) {
//                if (config.getVipGrade().equals(couponVip.getVipGrade())) {
//                    vipGradeConfig = config;
//                }
//            }
//            if (Objects.isNull(vipGradeConfig)) {
//                return;
//            }
//
//            LocalDate localDate = couponVip.getVipGradeDate().minusMonths(vipGradeConfig.getSettingDate());
//
//            if (LocalDate.now().isEqual(couponVip.getVipGradeDate())) {
//                List<VipBankInfo> byVipIdAndSettingTime = couponVipBankInfoDao.getByVipIdAndSettingTime(String.valueOf(couponVip.getVipId()), localDate);
//                Long sco = byVipIdAndSettingTime.stream().mapToLong(VipBankInfo::getScoring).sum();
//                Integer grade = 0;
//                LocalDate endDate = LocalDate.now();
//                for (VipGradeConfig config : list) {
//                    if (sco <= config.getRatingEnd() && sco > config.getRatingStart()) {
//                        grade = config.getVipGrade();
//                        endDate = endDate.plusMonths(config.getSettingDate());
//                    }
//                }
//                couponVip.setVipGrade(grade);
//                couponVip.setVipGradeDate(endDate);
//                couponVipDao.updateById(couponVip);
//            }

//        });
//        List<VipGradeConfig> list = vipGradeConfigDao.list();
//        if (CollectionUtils.isEmpty(list)){
//            log.warn("【MemberManagementServiceImpl editMemberGrade】 会员等级未配置");
//            return BaseResult.defaultFail();
//        }
//        list.forEach(vipGradeConfig -> {
//
//            LocalDate settingTime = vipGradeConfig.getSettingTime();
//            LocalDate localDate ;
//            switch (vipGradeConfig.getDateType()){
//                case 1:
//                    localDate = settingTime.plusDays(vipGradeConfig.getSettingDate());
//                    break;
//                case 2:
//                    localDate = settingTime.plusMonths(vipGradeConfig.getSettingDate());
//                    break;
//                case 3:
//                    localDate = settingTime.plusYears(vipGradeConfig.getSettingDate());
//                    break;
//                default:
//                    log.error("【MemberManagementServiceImpl editMemberGrade】 不存在的日期类型");
//                    return;
//            }
//            boolean equal = localDate.isEqual(LocalDate.now());
//            if (equal){
//                updateMemberGrade(vipGradeConfig);
//            }
//        });
        return BaseResult.success("success");
    }


////    @Async("taskAsyncPool")
//    @Override
//    public void cardDataUpdate(String filePath) {
//
//        //银行卡表	日	增量		数据文件	m_ud_gxd_card.unl
//        String fileName = "m_ud_gxd_card.unl";
//        log.info("【VipBankInfoServiceImpl cardDataUpdate】start====>{}", fileName + fileName);
//        List<ConditionsName> conditionsNameByClassId = conditionsNameDao.findConditionsNameByClassIdAndSetStatus(BankFileTypeEnum.BANK_CARD_DATA_INFO.getCode() + "");
//        if (CollectionUtils.isEmpty(conditionsNameByClassId)) {
//            return;
//        }
//
//        int nThreads = 50;
//        // 创建一个最大线程数为 @nThreads 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
//        // 创建一个队列用于子线程共享数据
//        ArrayBlockingQueue<String> dateLineQueue = new ArrayBlockingQueue<String>(100000);
//
//        Thread cust = new Thread(() -> {
//            String line = null;
//            try {
//                List<BankCardDataInfo> list = new ArrayList<>();
//                BankCardDataInfo bankCardDataInfo;
//                Long count = 0L;
//                while (true) {
//                    line = dateLineQueue.poll(5, TimeUnit.SECONDS);
//                    if (!StringUtils.hasText(line)) {
//                        if (executorService.isShutdown()) {
//                            log.info(Thread.currentThread().getName() + "- 线程池已关闭，处理完当前子线程list后，结束当前子线程");
//                            if (list.size() > BasicConstant.INT_0) {
//                                bankCardDataInfoDao.saveBatch(list);
//                                count += list.size();
//                            }
//                            break;
//                        }
//                        continue;
//                    }
//
//                    bankCardDataInfo = new BankCardDataInfo();
//                    String[] values = line.split("\u0001");
//                    for (int i = 0; i < values.length; i++) {
//                        for (ConditionsName conditionsName : conditionsNameByClassId) {
//                            if (conditionsName.getSetValueStatus() == BasicConstant.INT_0 && (i + 1) == conditionsName.getConditionsValueKeyIndex()) {
//                                String value = values[i];
//                                if (StringUtils.isEmpty(value)) {
//                                    continue;
//                                }
//                                if ("cardCategory".equals(conditionsName.getConditionsValueKey())) {
//
//                                    if (!StringUtils.isEmpty(value)) {
//                                        if ("A01".equals(value)) {
//                                            value = "1";
//                                        } else if ("A02".equals(value)) {
//                                            value = "2";
//                                        } else if ("A03".equals(value)) {
//                                            value = "3";
//                                        }
//                                    }
//
//                                }
//                                setValue(bankCardDataInfo, conditionsName.getConditionsValueKey(), value);
//                            }
//                        }
//                    }
//
//                    if (!StringUtils.isEmpty(bankCardDataInfo.getBankCardNumber())) {
//                        bankCardDataInfo.setCardBin(bankCardDataInfo.getBankCardNumber().substring(0, 6));
//                    }
//                    bankCardDataInfo.setCardType("1");
//                    bankCardDataInfo.setUpdateTime(LocalDateTime.now());
//                    BankCardDataInfo id = bankCardDataInfoDao.getIdByCardNo(bankCardDataInfo.getBankCardNumber());
//                    if (Objects.nonNull(id)) {
//                        bankCardDataInfo.setId(id.getId());
//                    }
//
//                    list.add(bankCardDataInfo);
//                    if (BasicConstant.INT_1000 == list.size()) {
//                        bankCardDataInfoDao.saveBatch(list);
//                        count += list.size();
//                        list.clear();
//                        log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "已完成" + count);
//                    }
//                }
//                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "全部处理完成共" + count);
//
//            } catch (Exception e) {
//                log.error(Thread.currentThread().getName() + " line = {}", line, e);
//            }
//        });
//
//        for (int i = 0; i < nThreads - 1; i++) {
//            executorService.submit(cust);
//        }
//
//        try {
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath + fileName));
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                dateLineQueue.put(line);
//            }
//            log.info("【VipBankInfoServiceImpl cardDataUpdate】文件数据读取完毕");
//            // todo 读取完毕后自己也不能闲着，可以继续处理数据，这里留着以后优化，现在足够用了
//
//            int errNum = 0;
//            while (!dateLineQueue.isEmpty()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl cardDataUpdate 】dateLineQueue处理异常");
//                }
//                Thread.sleep(1000);
//            }
//            errNum = 0;
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl cardDataUpdate 】executorService shutdown异常");
//                }
//                Thread.sleep(1000);
//            }
//            log.info("【VipBankInfoServiceImpl cardDataUpdate】子线程全部完成");
//        } catch (Exception e) {
//            log.error("【VipBankInfoServiceImpl cardDataUpdate】",e);
//            throw new BaseException(ErrorCodeEnums.BANK_DATA_READ_IS_ERROR);
//        }
//
//        log.info("【VipBankInfoServiceImpl cardDataUpdate】end====>{}",fileName+fileName);
//    }
//
////    @Async("taskAsyncPool")
//    @Override
//    public void productDataInfo(String filePath) {
//        //个人客户业务表	日	全量 	数据文件	m_ud_gxd_indv_cust_busi.unl
//        String fileName = "m_ud_gxd_indv_cust_busi.unl";
//        log.info("【VipBankInfoServiceImpl productDataInfo】start====>{}", fileName + fileName);
//        List<ConditionsName> conditionsNameByClassId = conditionsNameDao.findConditionsNameByClassIdAndSetStatus(BankFileTypeEnum.BANK_PRODUCT_DATA_INFO.getCode() + "");
//        if (CollectionUtils.isEmpty(conditionsNameByClassId)) {
//            return;
//        }
//        bankProductDataInfoDao.truncate(); //TRUNCATE 到时候看是否单独拆出
//
//        int nThreads = 50;
//        // 创建一个最大线程数为 @nThreads 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
//        // 创建一个队列用于子线程共享数据
//        ArrayBlockingQueue<String> dateLineQueue = new ArrayBlockingQueue<String>(100000);
//
//        Thread cust = new Thread(() -> {
//            String line = null;
//            try {
//                List<BankProductDataInfo> list = new ArrayList<>();
//                BankProductDataInfo bankProductDataInfo;
//                Long count = 0L;
//                while (true) {
//                    line = dateLineQueue.poll(5, TimeUnit.SECONDS);
//                    if (!StringUtils.hasText(line)) {
//                        if (executorService.isShutdown()) {
//                            log.info(Thread.currentThread().getName() + "- 线程池已关闭，处理完当前子线程list后，结束当前子线程");
//                            if (list.size() > BasicConstant.INT_0) {
//                                bankProductDataInfoDao.saveBatch(list);
//                                count += list.size();
//                            }
//                            break;
//                        }
//                        continue;
//                    }
//                    bankProductDataInfo = new BankProductDataInfo();
//                    String[] values = line.split("\u0001");
//                    for (int i = 0; i < values.length; i++) {
//                        for (ConditionsName conditionsName : conditionsNameByClassId) {
//                            if (conditionsName.getSetValueStatus() == BasicConstant.INT_0 && (i + 1) == conditionsName.getConditionsValueKeyIndex()) {
//                                String value = values[i];
//                                if (StringUtils.isEmpty(value)) {
//                                    continue;
//                                }
//                                if ("type".equals(conditionsName.getConditionsValueKey())) {
//
//                                    if (!StringUtils.isEmpty(value)) {
//                                        if ("CH".equals(value)) {
//                                            value = "1";
//                                        } else if ("TD".equals(value)) {
//                                            value = "2";
//                                        }
//                                    }
//
//                                }
//                                if ("deadline".equals(conditionsName.getConditionsValueKey())) {
//                                    value = value.substring(2);
//                                }
//                                setValue(bankProductDataInfo, conditionsName.getConditionsValueKey(), value);
//                            }
//                        }
//                    }
//                    list.add(bankProductDataInfo);
//                    if (BasicConstant.INT_1000 == list.size()) {
//                        bankProductDataInfoDao.saveBatch(list);
//                        count += list.size();
//                        list.clear();
//                        log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "已完成" + count);
//                    }
//                }
//                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "全部处理完成共" + count);
//
//            } catch (Exception e) {
//                log.error(Thread.currentThread().getName() + " line = {}", line, e);
//            }
//        });
//
//        for (int i = 0; i < nThreads; i++) {
//            executorService.submit(cust);
//        }
//
//        try {
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath + fileName));
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                dateLineQueue.put(line);
//            }
//            log.info("【VipBankInfoServiceImpl productDataInfo】文件数据读取完毕");
//            // todo 读取完毕后自己也不能闲着，可以继续处理数据，这里留着以后优化，现在足够用了
//
//            int errNum = 0;
//            while (!dateLineQueue.isEmpty()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl productDataInfo 】dateLineQueue处理异常");
//                }
//                Thread.sleep(1000);
//            }
//            errNum = 0;
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl productDataInfo 】executorService shutdown异常");
//                }
//                Thread.sleep(1000);
//            }
//            log.info("【VipBankInfoServiceImpl bankPrivatePrimitiveUpdate】子线程全部完成");
//
//        } catch (Exception e) {
//            log.error("【VipBankInfoServiceImpl productDataInfo】",e);
//            throw new BaseException(ErrorCodeEnums.BANK_DATA_READ_IS_ERROR);
//        }
//        log.info("【VipBankInfoServiceImpl productDataInfo】end====>{}",fileName+fileName);
//    }
//
////    @Async("taskAsyncPool")
//    @Override
//    public void customerSignUpdate(String filePath) {
//
//        //个人客户签约表	日	增量		数据文件	m_ud_gxd_indv_cust_sign.unl
//        String fileName = "m_ud_gxd_indv_cust_sign.unl";
//        log.info("【VipBankInfoServiceImpl customerSignUpdate】start====>{}", filePath + fileName);
//        List<ConditionsName> conditionsNameByClassId = conditionsNameDao.findConditionsNameByClassIdAndSetStatus(BankFileTypeEnum.BANK_CUSTOMER_SIGN_INFO.getCode() + "");
//        if (CollectionUtils.isEmpty(conditionsNameByClassId)) {
//            return;
//        }
//
//        int nThreads = 50;
//        // 创建一个最大线程数为 @nThreads 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
//        // 创建一个队列用于子线程共享数据
//        ArrayBlockingQueue<String> dateLineQueue = new ArrayBlockingQueue<String>(100000);
//
//        Thread cust = new Thread(() -> {
//            String line = null;
//            try {
//                List<BankCustomerSignInfo> list = new ArrayList<>();
//                BankCustomerSignInfo bankCustomerSignInfo;
//                Long count = 0L;
//                while (true) {
//                    line = dateLineQueue.poll(5, TimeUnit.SECONDS);
//                    if (!StringUtils.hasText(line)) {
//                        if (executorService.isShutdown()) {
//                            log.info(Thread.currentThread().getName() + "- 线程池已关闭，处理完当前子线程list后，结束当前子线程");
//                            if (list.size() > BasicConstant.INT_0) {
//                                bankCustomerSignInfoDao.saveBatch(list);
//                                count += list.size();
//                            }
//                            break;
//                        }
//                        continue;
//                    }
//
//                    bankCustomerSignInfo = new BankCustomerSignInfo();
//                    String[] values = line.split("\u0001");
//                    for (int i = 0; i < values.length; i++) {
//                        for (ConditionsName conditionsName : conditionsNameByClassId) {
//                            if (conditionsName.getSetValueStatus() == BasicConstant.INT_0 && (i + 1) == conditionsName.getConditionsValueKeyIndex()) {
//                                String value = values[i];
//                                if (StringUtils.isEmpty(value)) {
//                                    continue;
//                                }
//                                if ("signServer".equals(conditionsName.getConditionsValueKey())) {
//
//                                    if (!StringUtils.isEmpty(value)) {
//                                        if ("0101".equals(value)) {
//                                            value = "1";
//                                        } else if ("0102".equals(value)) {
//                                            value = "2";
//                                        }
//                                    }
//
//                                }
//                                setValue(bankCustomerSignInfo, conditionsName.getConditionsValueKey(), value);
//                            }
//                        }
//                    }
//                    BankCustomerSignInfo id = bankCustomerSignInfoDao.getByCstIdAndSignServer(bankCustomerSignInfo.getCstId(), bankCustomerSignInfo.getSignServer());
//                    if (Objects.nonNull(id)) {
//                        bankCustomerSignInfo.setId(id.getId());
//                    }
//                    list.add(bankCustomerSignInfo);
//                    if (BasicConstant.INT_1000 == list.size()) {
//                        bankCustomerSignInfoDao.saveBatch(list);
//                        count += list.size();
//                        list.clear();
//                        log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "已完成" + count);
//                    }
//                }
//                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "全部处理完成共" + count);
//
//            } catch (Exception e) {
//                log.error(Thread.currentThread().getName() + " line = {}", line, e);
//            }
//        });
//
//        for (int i = 0; i < nThreads - 1; i++) {
//            executorService.submit(cust);
//        }
//
//        try {
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath + fileName));
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                dateLineQueue.put(line);
//            }
//            log.info("【VipBankInfoServiceImpl customerSignUpdate】文件数据读取完毕");
//            // todo 读取完毕后自己也不能闲着，可以继续处理数据，这里留着以后优化，现在足够用了
//
//            int errNum = 0;
//            while (!dateLineQueue.isEmpty()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl customerSignUpdate 】dateLineQueue处理异常");
//                }
//                Thread.sleep(1000);
//            }
//            errNum = 0;
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl customerSignUpdate 】executorService shutdown异常");
//                }
//                Thread.sleep(1000);
//            }
//            log.info("【VipBankInfoServiceImpl customerSignUpdate】子线程全部完成");
//        } catch (Exception e) {
//            log.error("【VipBankInfoServiceImpl customerSignUpdate】",e);
//            throw new BaseException(ErrorCodeEnums.BANK_DATA_READ_IS_ERROR);
//        }
//        log.info("【VipBankInfoServiceImpl customerSignUpdate】end====>{}",fileName+fileName);
//    }
//
//    @Async("taskAsyncPool")
//    public void merchantInfoUpdate(String filePath) {
//
//        //商户表	日	全量		数据文件	m_ud_gxd_mrch.unl
//        String fileName = "m_ud_gxd_mrch.unl";
//        log.info("【VipBankInfoServiceImpl merchantInfoUpdate】start====>{}", filePath + fileName);
//        List<ConditionsName> conditionsNameByClassId = conditionsNameDao.findConditionsNameByClassIdAndSetStatus(BankFileTypeEnum.BANK_PUBLIC_PRIMITIVE.getCode() + "");
//        if (CollectionUtils.isEmpty(conditionsNameByClassId)) {
//            return;
//        }
//        // 由于 m_ud_gxd_mrch 是全量数据，所以在接受数据前，将表清空
////        bankPublicPrimitiveDao.truncate();
//
//        int nThreads = 50;
//        // 创建一个最大线程数为 @nThreads 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
//        // 创建一个队列用于子线程共享数据
//        ArrayBlockingQueue<String> dateLineQueue = new ArrayBlockingQueue<String>(100000);
//
//        Thread cust = new Thread(() -> {
//            String line = null;
//            try {
//                List<BankPublicPrimitive> list = new ArrayList<>();
//                BankPublicPrimitive bankPublicPrimitive;
//                Long count = 0L;
//                while (true) {
//                    line = dateLineQueue.poll(5, TimeUnit.SECONDS);
//                    if (!StringUtils.hasText(line)) {
//                        if (executorService.isShutdown()) {
//                            log.info(Thread.currentThread().getName() + "- 线程池已关闭，处理完当前子线程list后，结束当前子线程");
//                            if (list.size() > BasicConstant.INT_0) {
//                                bankPublicPrimitiveDao.saveBatch(list);
//                                count += list.size();
//                            }
//                            break;
//                        }
//                        continue;
//                    }
//
//                    bankPublicPrimitive = new BankPublicPrimitive();
//                    String[] values = line.split("\u0001");
//                    for (int i = 0; i < values.length; i++) {
//                        for (ConditionsName conditionsName : conditionsNameByClassId) {
//                            if (conditionsName.getSetValueStatus() == BasicConstant.INT_0 && (i + 1) == conditionsName.getConditionsValueKeyIndex()) {
//                                String value = values[i];
//                                if (StringUtils.isEmpty(value)) {
//                                    continue;
//                                }
//                                if ("mctRegisterYears".equals(conditionsName.getConditionsValueKey())) {
//                                    if (!StringUtils.isEmpty(value)) {
//                                        LocalDate localDate = DateTimeUtil.parseDateFormatStr(value);
//                                        Period period = Period.between(localDate, LocalDate.now());
//                                        value = "" + period.getYears();
//                                    }
//                                }
//
//                                setValue(bankPublicPrimitive, conditionsName.getConditionsValueKey(), value);
//                            }
//                        }
//                    }
//                    bankPublicPrimitive.setMctGrade(0);
//                    bankPublicPrimitive.setMctRegTime(LocalDateTime.now());
//                    bankPublicPrimitive.setMctRegType(0);
//                    bankPublicPrimitive.setMctAgoGrow(0L);
//                    bankPublicPrimitive.setUpdateTime(LocalDate.now());
//                    list.add(bankPublicPrimitive);
//                    if (BasicConstant.INT_1000 == list.size()) {
//                        bankPublicPrimitiveDao.saveBatch(list);
//                        count += list.size();
//                        list.clear();
//                        log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "已完成" + count);
//                    }
//                }
//                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "全部处理完成共" + count);
//
//            } catch (Exception e) {
//                log.error(Thread.currentThread().getName() + " line = {}", line, e);
//            }
//        });
//
//        for (int i = 0; i < nThreads - 1; i++) {
//            executorService.submit(cust);
//        }
//
//
//        try {
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath + fileName));
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//
//                dateLineQueue.put(line);
//            }
//            log.info("【VipBankInfoServiceImpl merchantInfoUpdate】文件数据读取完毕");
//            // todo 读取完毕后自己也不能闲着，可以继续处理数据，这里留着以后优化，现在足够用了
//
//            int errNum = 0;
//            while (!dateLineQueue.isEmpty()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl merchantInfoUpdate 】dateLineQueue处理异常");
//                }
//                Thread.sleep(1000);
//            }
//            errNum = 0;
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl merchantInfoUpdate 】executorService shutdown异常");
//                }
//                Thread.sleep(1000);
//            }
//            log.info("【VipBankInfoServiceImpl merchantInfoUpdate】子线程全部完成");
//        } catch (Exception e) {
//            log.error("【VipBankInfoServiceImpl merchantInfoUpdate】",e);
//            throw new BaseException(ErrorCodeEnums.BANK_DATA_READ_IS_ERROR);
//        }
//
//        log.info("【VipBankInfoServiceImpl merchantInfoUpdate】end====>{}",fileName+fileName);
//    }
//
//    @Async("taskAsyncPool")
//    public void vipInfoUpdate(String filePath) {
//
//        //个人客户信息表	日	增量		数据文件	QYYX_CUSTOM_INFO.unl
//        String fileName = "QYYX_CUSTOM_INFO.unl";
//        log.info("【VipBankInfoServiceImpl vipInfoUpdate】start====>{}", filePath + fileName);
//        List<ConditionsName> conditionsNameByClassId = conditionsNameDao.findConditionsNameByClassIdAndSetStatus(BankFileTypeEnum.BANK_CUSTOMER_INFO.getCode() + "");
//        if (CollectionUtils.isEmpty(conditionsNameByClassId)) {
//            return;
//        }
//
//        int nThreads = 50;
//        // 创建一个最大线程数为 @nThreads 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
//        // 创建一个队列用于子线程共享数据
//        ArrayBlockingQueue<String> dateLineQueue = new ArrayBlockingQueue<String>(100000);
//
//        Thread cust = new Thread(() -> {
//            String line = null;
//            try {
//                List<VipInfo> list = new ArrayList<>();
//                VipInfo vipInfo;
//                Long count = 0L;
//                while (true) {
//                    line = dateLineQueue.poll(5, TimeUnit.SECONDS);
//                    if (!StringUtils.hasText(line)) {
//                        if (executorService.isShutdown()) {
//                            log.info(Thread.currentThread().getName() + "- 线程池已关闭，处理完当前子线程list后，结束当前子线程");
//                            if (list.size() > BasicConstant.INT_0) {
//                                vipInfoDao.saveBatch(list);
//                                count += list.size();
//                            }
//                            break;
//                        }
//                        continue;
//                    }
//
//                    vipInfo = new VipInfo();
//                    String[] values = line.split("\u0001");
//                    for (int i = 0; i < values.length; i++) {
//                        for (ConditionsName conditionsName : conditionsNameByClassId) {
//                            if (conditionsName.getSetValueStatus() == BasicConstant.INT_0 && (i + 1) == conditionsName.getConditionsValueKeyIndex()) {
//                                String value = values[i];
//                                if (StringUtils.isEmpty(value)) {
//                                    continue;
//                                }
//                                if ("vipSex".equals(conditionsName.getConditionsValueKey())) {
//                                    if (!"1".equals(value) && !"2".equals(value)) {
//                                        value = "0";
//                                    }
//                                }
//                                if ("vipAge".equals(conditionsName.getConditionsValueKey())) {
//                                    if (!StringUtils.isEmpty(value)) {
//                                        if (value.length() != BasicConstant.INT_8) {
//                                            continue;
//                                        }
//                                        LocalDate localDate = null;
//                                        try {
//                                            localDate = DateTimeUtil.parseDateFormatStr(value);
//                                        } catch (Exception e) {
//                                            log.error("【VipBankInfoServiceImpl vipInfoUpdate】localDtate===>{}", value, e);
//                                            continue;
//                                        }
//                                        Period period = Period.between(localDate, LocalDate.now());
//                                        value = "" + period.getYears();
//                                    }
//                                }
//                                setValue(vipInfo, conditionsName.getConditionsValueKey(), value);
//                            }
//                        }
//                    }
//                    VipInfo id = vipInfoDao.getByCstIdSelectId(vipInfo.getVipCstId());
//                    if (Objects.nonNull(id)) {
//                        vipInfo.setVipId(id.getVipId());
//                    } else {
//                        vipInfo.setVipGrade(Double.valueOf(0));
//                        vipInfo.setVipRegTime(LocalDateTime.now());
//                        vipInfo.setVipRegType(0);
//                        vipInfo.setVipAgoGrow(0L);
//                    }
//                    vipInfo.setUpdateTime(LocalDateTime.now());
//                    list.add(vipInfo);
//                    if (BasicConstant.INT_1000 == list.size()) {
//                        vipInfoDao.saveBatch(list);
//                        count += list.size();
//                        list.clear();
//                        log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "已完成" + count);
//                    }
//                }
//                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "全部处理完成共" + count);
//
//            } catch (Exception e) {
//                log.error(Thread.currentThread().getName() + " line = {}", line, e);
//            }
//        });
//
//        for (int i = 0; i < nThreads - 1; i++) {
//            executorService.submit(cust);
//        }
//
//        try {
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath + fileName));
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                dateLineQueue.put(line);
//            }
//            log.info("【VipBankInfoServiceImpl vipInfoUpdate】文件数据读取完毕");
//            // todo 读取完毕后自己也不能闲着，可以继续处理数据，这里留着以后优化，现在足够用了
//
//            int errNum = 0;
//            while (!dateLineQueue.isEmpty()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl vipInfoUpdate 】dateLineQueue处理异常");
//                }
//                Thread.sleep(1000);
//            }
//            errNum = 0;
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl vipInfoUpdate 】executorService shutdown异常");
//                }
//                Thread.sleep(1000);
//            }
//            log.info("【VipBankInfoServiceImpl vipInfoUpdate】子线程全部完成");
//        } catch (Exception e) {
//            log.error("【VipBankInfoServiceImpl vipInfoUpdate】", e);
//            throw new BaseException(ErrorCodeEnums.BANK_DATA_READ_IS_ERROR);
//        }
//        log.info("【VipBankInfoServiceImpl vipInfoUpdate】end====>{}", filePath + fileName);
//    }
//
//    /**
//     * 快捷支付卡签约信息
//     *
//     * @param filePath
//     */
//    @Override
//    public void bankCardBindingInfoUpdate(String filePath) {
//        //  快捷支付签约表	日	增量		数据文件	m_ud_gxd_indv_qkpy_sign.unl
//        String fileName = "m_ud_gxd_indv_qkpy_sign.unl";
//        log.info("【VipBankInfoServiceImpl bankCardBindingInfoUpdate】start====>{}", filePath + fileName);
//        List<ConditionsName> conditionsNameByClassId = conditionsNameDao.findConditionsNameByClassIdAndSetStatus(BankFileTypeEnum.BANK_CARD_BINDING_INFO.getCode() + "");
//        if (CollectionUtils.isEmpty(conditionsNameByClassId)) {
//            return;
//        }
//
//        int nThreads = 50;
//        // 创建一个最大线程数为 @nThreads 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
//        // 创建一个队列用于子线程共享数据
//        ArrayBlockingQueue<String> dateLineQueue = new ArrayBlockingQueue<String>(100000);
//
//        Thread cust = new Thread(() -> {
//            String line = null;
//            try {
//                List<BankCardBindingInfo> list = new ArrayList<>();
//                List<String> existWhere = new ArrayList<>();
//                BankCardBindingInfo bankCardBindingInfo;
//                Long count = 0L;
//                while (true) {
//                    line = dateLineQueue.poll(5, TimeUnit.SECONDS);
//                    if (!StringUtils.hasText(line)) {
//                        if (executorService.isShutdown()) {
//                            log.info(Thread.currentThread().getName() + "- 线程池已关闭，处理完当前子线程list后，结束当前子线程");
//                            if (list.size() > BasicConstant.INT_0) {
//                                Map<String, Long> idMap = Collections.emptyMap();
//                                if (!CollectionUtils.isEmpty(idMap)) {
//                                    for (BankCardBindingInfo b : list) {
//                                        b.setId(idMap.get(b.getBankCardNumber() + b.getBindingCardProduct()));
//                                    }
//                                }
//                                bankCardBindingInfoDao.saveOrUpdateBatch(list);
//                                list.clear();
//                                existWhere.clear();
//                                count += list.size();
//                                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "最终已完成" + count);
//                            }
//                            break;
//                        }
//                        continue;
//                    }
//
//                    bankCardBindingInfo = new BankCardBindingInfo();
//                    String[] values = line.split("\u0001");
//                    for (int i = 0; i < values.length; i++) {
//                        for (ConditionsName conditionsName : conditionsNameByClassId) {
//                            if (conditionsName.getSetValueStatus() == BasicConstant.INT_0 && (i + 1) == conditionsName.getConditionsValueKeyIndex()) {
//                                String value = values[i];
//                                if (StringUtils.isEmpty(value)) {
//                                    continue;
//                                }
//                                if ("bindingCardProduct".equals(conditionsName.getConditionsValueKey())) {
//                                    value = value;
//                                }
//                                if ("bindingCardTime".equals(conditionsName.getConditionsValueKey())) {
//                                    if (!StringUtils.isEmpty(value)) {
//                                        if (value.length() != BasicConstant.INT_8) {
//                                            continue;
//                                        }
//                                        LocalDate localDate = null;
//                                        try {
//                                            localDate = DateTimeUtil.parseDateFormatStr(value);
//                                        } catch (Exception e) {
//                                            log.error("【VipBankInfoServiceImpl bankCardBindingInfoUpdate】localDtate===>{}", value, e);
//                                            continue;
//                                        }
//                                    }
//                                }
//                                setValue(bankCardBindingInfo, conditionsName.getConditionsValueKey(), value);
//                            }
//                        }
//                    }
//                    existWhere.add("'" + bankCardBindingInfo.getBankCardNumber() + "','" + bankCardBindingInfo.getBindingCardProduct() + "'");
//                    bankCardBindingInfo.setUpdateTime(LocalDateTime.now());
//                    list.add(bankCardBindingInfo);
//                    if (BasicConstant.INT_1000 == list.size()) {
//                        Map<String, Long> idMap = Collections.emptyMap();
//                        if (!CollectionUtils.isEmpty(idMap)) {
//                            for (BankCardBindingInfo b : list) {
//                                b.setId(idMap.get(b.getBankCardNumber() + b.getBindingCardProduct()));
//                            }
//                        }
//                        bankCardBindingInfoDao.saveOrUpdateBatch(list);
//                        count += list.size();
//                        list.clear();
//                        existWhere.clear();
//                        log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "已完成" + count);
//
//                    }
//                }
//                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "全部处理完成共" + count);
//
//            } catch (Exception e) {
//                log.error(Thread.currentThread().getName() + " line = {}", line, e);
//            }
//        });
//
//        for (int i = 0; i < nThreads - 1; i++) {
//            executorService.submit(cust);
//        }
//        BankCardBindingInfo bankCardBindingInfo = new BankCardBindingInfo();
//        Long count = 0L;
//        try {
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath + fileName));
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                dateLineQueue.put(line);
//            }
//            log.info("【VipBankInfoServiceImpl bankCardBindingInfoUpdate】文件数据读取完毕");
//            // todo 读取完毕后自己也不能闲着，可以继续处理数据，这里留着以后优化，现在足够用了
//
//            int errNum = 0;
//            while (!dateLineQueue.isEmpty()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl bankCardBindingInfoUpdate 】dateLineQueue处理异常");
//                }
//                Thread.sleep(1000);
//            }
//            errNum = 0;
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl bankCardBindingInfoUpdate 】executorService shutdown异常");
//                }
//                Thread.sleep(1000);
//            }
//            log.info("【VipBankInfoServiceImpl bankCardBindingInfoUpdate】子线程全部完成");
//        } catch (Exception e) {
//            log.error("【VipBankInfoServiceImpl bankCardBindingInfoUpdate】{}", JsonUtils.objectToJson(bankCardBindingInfo), e);
//            throw new BaseException(ErrorCodeEnums.BANK_DATA_READ_IS_ERROR);
//        }
//        log.info("【VipBankInfoServiceImpl bankCardBindingInfoUpdate】end====>{}", filePath + fileName);
//    }
//
//    /**
//     * 个人客户AUM
//     *
//     * @param filePath
//     */
//    @Override
//    public void bankPrivatePrimitiveUpdate(String filePath) {
//
//        String fileName = "m_ud_gxd_indv_cust_aum.unl";
//        log.info("【VipBankInfoServiceImpl bankPrivatePrimitiveUpdate】start====>{}", filePath + fileName);
//        List<ConditionsName> conditionsNameByClassId = conditionsNameDao.findConditionsNameByClassIdAndSetStatus(BankFileTypeEnum.BANK_PRIVATE_PRIMITIVE.getCode() + "");
//        if (CollectionUtils.isEmpty(conditionsNameByClassId)) {
//            return;
//        }
//        // 由于m_ud_gxd_indv_cust_aum是全量数据，所以在接受数据前，将表清空
//        bankPrivatePrimitiveDao.truncate();
//
//        int nThreads = 50;
//        // 创建一个最大线程数为 @nThreads 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
//        // 创建一个队列用于子线程共享数据
//        ArrayBlockingQueue<String> dateLineQueue = new ArrayBlockingQueue<String>(100000);
//
//        Thread cust = new Thread(() -> {
//            String line = null;
//            try {
//                List<BankPrivatePrimitive> list = new ArrayList<>();
//                BankPrivatePrimitive bankPrivatePrimitive;
//                Long count = 0L;
//                while (true) {
//                    line = dateLineQueue.poll(5, TimeUnit.SECONDS);
//                    if (!StringUtils.hasText(line)) {
//                        if (executorService.isShutdown()) {
//                            log.info(Thread.currentThread().getName() + "- 线程池已关闭，处理完当前子线程list后，结束当前子线程");
//                            if (list.size() > BasicConstant.INT_0) {
//                                bankPrivatePrimitiveDao.saveBatch(list);
//                                count += list.size();
//                            }
//                            break;
//                        }
//                        continue;
//                    }
//
//                    bankPrivatePrimitive = new BankPrivatePrimitive();
//                    String[] values = line.split("\u0001");
//                    for (int i = 0; i < values.length; i++) {
//                        for (ConditionsName conditionsName : conditionsNameByClassId) {
//                            if (conditionsName.getSetValueStatus() == BasicConstant.INT_0 && (i + 1) == conditionsName.getConditionsValueKeyIndex()) {
//                                String value = values[i];
//                                if (StringUtils.isEmpty(value)) {
//                                    continue;
//                                }
//                                setValue(bankPrivatePrimitive, conditionsName.getConditionsValueKey(), value);
//                            }
//                        }
//                    }
//                    bankPrivatePrimitive.setUpdateTime(LocalDateTime.now());
//                    list.add(bankPrivatePrimitive);
//                    if (BasicConstant.INT_1000 == list.size()) {
//                        bankPrivatePrimitiveDao.saveBatch(list);
//                        count += list.size();
//                        list.clear();
//                        log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "已完成" + count);
//                    }
//                }
//                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "全部处理完成共" + count);
//
//            } catch (Exception e) {
//                log.error(Thread.currentThread().getName() + " line = {}", line, e);
//            }
//        });
//
//        for (int i = 0; i < nThreads - 1; i++) {
//            executorService.submit(cust);
//        }
//
//        try {
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath + fileName), 40 * 1024);
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                dateLineQueue.put(line);
//            }
//            log.info("【VipBankInfoServiceImpl bankPrivatePrimitiveUpdate】文件数据读取完毕");
//            // todo 读取完毕后自己也不能闲着，得接数据
//
//            int errNum = 0;
//            while (!dateLineQueue.isEmpty()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl bankPrivatePrimitiveUpdate 】dateLineQueue处理异常");
//                }
//                Thread.sleep(1000);
//            }
//            errNum = 0;
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl bankPrivatePrimitiveUpdate 】executorService shutdown异常");
//                }
//                Thread.sleep(1000);
//            }
//            log.info("【VipBankInfoServiceImpl bankPrivatePrimitiveUpdate】子线程全部完成");
//        } catch (Exception e) {
//            log.error("【VipBankInfoServiceImpl bankPrivatePrimitiveUpdate】", e);
//            throw new BaseException(ErrorCodeEnums.BANK_DATA_READ_IS_ERROR);
//        }
//        log.info("【VipBankInfoServiceImpl bankPrivatePrimitiveUpdate】end====>{}", filePath + fileName);
//    }
//
//
//    @Async("taskAsyncPool")
//    public void merchantTradeInfo(String filePath) {
//        //商户交易统计表	日	全量		数据文件	m_ud_gxd_mrch_txn_stat.unl
//        String fileName = "m_ud_gxd_mrch_txn_stat.unl";
//        log.info("【VipBankInfoServiceImpl merchantTradeInfo】start====>{}", filePath + fileName);
//
//        List<ConditionsName> conditionsNameByClassId = conditionsNameDao.findConditionsNameByClassIdAndSetStatus(BankFileTypeEnum.BANK_PUBLIC_TRADE_PRIMITIVE.getCode() + "");
//        if (CollectionUtils.isEmpty(conditionsNameByClassId)) {
//            return;
//        }
//
//        // 由于 m_ud_gxd_mrch_txn_stat 是全量数据，所以在接受数据前，将表清空
//        bankPublicTradePrimitiveDao.truncate();
//
//        int nThreads = 50;
//        // 创建一个最大线程数为 @nThreads 的线程池
//        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
//        // 创建一个队列用于子线程共享数据
//        ArrayBlockingQueue<String> dateLineQueue = new ArrayBlockingQueue<String>(100000);
//
//        Thread cust = new Thread(() -> {
//            String line = null;
//            try {
//                List<BankPublicTradePrimitive> list = new ArrayList<>();
//                BankPublicTradePrimitive bankPublicTradePrimitive;
//                Long count = 0L;
//                while (true) {
//                    line = dateLineQueue.poll(5, TimeUnit.SECONDS);
//                    if (!StringUtils.hasText(line)) {
//                        if (executorService.isShutdown()) {
//                            log.info(Thread.currentThread().getName() + "- 线程池已关闭，处理完当前子线程list后，结束当前子线程");
//                            if (list.size() > BasicConstant.INT_0) {
//                                bankPublicTradePrimitiveDao.saveBatch(list);
//                                count += list.size();
//                            }
//                            break;
//                        }
//                        continue;
//                    }
//
//                    bankPublicTradePrimitive = new BankPublicTradePrimitive();
//                    String[] values = line.split("\u0001");
//                    for (int i = 0; i < values.length; i++) {
//                        for (ConditionsName conditionsName : conditionsNameByClassId) {
//                            if (conditionsName.getSetValueStatus() == BasicConstant.INT_0 && (i + 1) == conditionsName.getConditionsValueKeyIndex()) {
//                                String value = values[i];
//                                if (StringUtils.isEmpty(value)) {
//                                    continue;
//                                }
//                                if ("tradeType".equals(conditionsName.getConditionsValueKey())) {
//                                    MerchantTradeTypeEnum byDec = MerchantTradeTypeEnum.getByDec(value);
//                                    if (Objects.isNull(byDec)) {
//                                        continue;
//                                    }
//                                    value = "" + byDec.getCode();
//                                }
//                                setValue(bankPublicTradePrimitive, conditionsName.getConditionsValueKey(), value);
//                            }
//                        }
//                    }
//                    list.add(bankPublicTradePrimitive);
//                    if (BasicConstant.INT_1000 == list.size()) {
//                        bankPublicTradePrimitiveDao.saveBatch(list);
//                        count += list.size();
//                        list.clear();
//                        log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "已完成" + count);
//                    }
//                }
//                log.info(Thread.currentThread().getName() + "-" + LocalDateTime.now() + "全部处理完成共" + count);
//
//            } catch (Exception e) {
//                log.error(Thread.currentThread().getName() + " line = {}", line, e);
//            }
//        });
//
//        for (int i = 0; i < nThreads - 1; i++) {
//            executorService.submit(cust);
//        }
//
//        try {
//            BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath + fileName));
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                dateLineQueue.put(line);
//            }
//            log.info("【VipBankInfoServiceImpl merchantTradeInfo】文件数据读取完毕");
//            // todo 读取完毕后自己也不能闲着，可以继续处理数据，这里留着以后优化，现在足够用了
//
//            int errNum = 0;
//            while (!dateLineQueue.isEmpty()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl merchantTradeInfo 】dateLineQueue处理异常");
//                }
//                Thread.sleep(1000);
//            }
//            errNum = 0;
//            executorService.shutdown();
//            while (!executorService.isTerminated()) {
//                errNum++;
//                if (errNum > 30) {
//                    throw new BaseException("【VipBankInfoServiceImpl merchantTradeInfo 】executorService shutdown异常");
//                }
//                Thread.sleep(1000);
//            }
//            log.info("【VipBankInfoServiceImpl merchantTradeInfo】子线程全部完成");
//        } catch (Exception e) {
//            log.error("【VipBankInfoServiceImpl merchantTradeInfo】",e);
//            throw new BaseException(ErrorCodeEnums.BANK_DATA_READ_IS_ERROR);
//        }
//
//
//        log.info("【VipBankInfoServiceImpl merchantTradeInfo】end====>{}",fileName+fileName);
//    }

    public static void setValue(Object obj,String fieldName,String value) {

        // 创建一个对象
//        PrivatePrimitive myObject = new PrivatePrimitive();

        // 获取字段的Class对象
//        Class<?> clazz = myObject.getClass();
        Class<?> clazz = obj.getClass();
        // 通过字段名获取Field对象
        Field field = null;
        try {
            field = clazz.getDeclaredField(fieldName);

            // 如果字段是私有的，需要设置setAccessible(true)来绕过访问权限检查
            field.setAccessible(true);

            if (field.getType().equals(Integer.class)) {
                // 如果属性是int类型，而值是String类型，尝试转换

                Integer intValue = Integer.parseInt(value);
                field.set(obj, intValue);
            }else if (field.getType().equals(Long.class)){
                Long intValue = Long.parseLong(value);
                field.set(obj, intValue);
            }else if (field.getType().equals(Double.class)){
                Double doubleValue = Double.parseDouble(value);
                field.set(obj, doubleValue);
            }else if (field.getType().equals(BigDecimal.class)){
                BigDecimal bigDecimalValue = new BigDecimal(value);
                field.set(obj, bigDecimalValue);
            }else if (field.getType().equals(LocalDateTime.class)){

                DateTime parse = cn.hutool.core.date.DateUtil.parse(value);
                LocalDateTime localDate =  LocalDateTimeUtil.of(parse);
                field.set(obj, localDate);
            }else if (field.getType().equals(LocalDate.class)){
                LocalDate localDate = DateTimeUtil.parseYYYYMMDD(getYYYYMMDDDate(value));
                field.set(obj, localDate);
            }else {
                // 直接设置值，确保类型匹配
                field.set(obj, value);
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            log.error("【ManageTagInfoServiceImpl.setValue赋值错误】",e);
            throw new BaseException(ErrorCodeEnums.BANK_FILE_SET_VALUE_ERROR);
        }


        // 给字段赋值
//        try {
//            field.set(obj, value);
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        }
    }

    public static String getYYYYMMDDDate(String date) {

//String result = date;

        String dateType = date.trim();

        dateType = dateType.replace("/", "").replace(".", "").replace("-", "").replace("年", "").replace("月", "").replace("日", "");

        return QxAndJhUtil.get8VaildDate(dateType);

    }

    public BaseResult vipSumGrowAndIntegral(RulesTypeEnum rulesTypeEnum) {
        if (Objects.isNull(rulesTypeEnum) || Objects.isNull(rulesTypeEnum.getTableName()) || Objects.isNull(rulesTypeEnum.getColumnName())){
            return BaseResult.defaultFail();
        }
        RulesList byId = rulesListDao.getById(rulesTypeEnum.getCode());
        if (Objects.isNull(byId)) {
            return BaseResult.defaultFail();
        }
        if (!RulesStatusEnum.OPEN.getValue().equals(byId.getStatus())){
            //已停用规则
            return BaseResult.success(true);
        }
        List<VipRatingConfig> rattingRulesListByRulesId = vipGradeRattingDao.getRattingRulesListByRulesId(String.valueOf(byId.getId()));
        if (Objects.isNull(rattingRulesListByRulesId) || CollectionUtils.isEmpty(rattingRulesListByRulesId)){
            throw new BaseException(ErrorCodeEnums.TASK_GROW_RULE_CONFIG_ERR.getErrcode(),ErrorCodeEnums.TASK_GROW_RULE_CONFIG_ERR.getMsg());
        }
        List<VipRatingConfig> sortedList = rattingRulesListByRulesId.stream().sorted(Comparator.comparingLong(VipRatingConfig::getRatingStart)).collect(Collectors.toList());
        //取出最高一档配置
        VipRatingConfig maxConfig = sortedList.get(sortedList.size()-1);
        //去除集合内最高档配置
        sortedList.remove(sortedList.size()-1);
        LocalDateTime nowTime = LocalDateTime.now();
        Integer nowDate = Integer.valueOf(DateTimeUtil.formatYYYYMMDD(LocalDate.now()));
        MctGrowAndIntegralSumDto sumDto = new MctGrowAndIntegralSumDto();
        sumDto.setTaskId(Long.valueOf(rulesTypeEnum.getCode()));
        sumDto.setType(VipGrowDetailTypeEnum.TYPE_0.getValue());
        sumDto.setTaskName(rulesTypeEnum.getName());
        sumDto.setDateTime(nowTime);
        sumDto.setMaxConfig(maxConfig);
        sumDto.setConfigs(sortedList);
        sumDto.setTbName(rulesTypeEnum.getTableName());
        sumDto.setColumnName(rulesTypeEnum.getColumnName());
        sumDto.setDate(nowDate);
        TagProducer tagProducer = null;
        vipGrowDetailDao.sumVipGrowAndIntegral(sumDto,tagProducer);
//        couponVipDao.updateGrowByTaskIdAndDate(byId.getId().longValue(),nowDate,nowTime);
        return BaseResult.success(true);
    }


}
